package com.synergy.stockflow.production.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.synergy.stockflow.production.mapper.ProductionTaskMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.synergy.stockflow.production.entity.ProductionPlan;
import com.synergy.stockflow.production.mapper.ProductionPlanMapper;
import com.synergy.stockflow.production.service.ProductionPlanService;

import java.util.List;

@Service
public class ProductionPlanServiceImpl extends ServiceImpl<ProductionPlanMapper, ProductionPlan> implements ProductionPlanService{

    @Autowired
    private ProductionTaskMapper productionTaskMapper;

    /**
     * 统计当月生产计划数量
     */
    @Override
    public int countCurrentMonthPlans() {
        QueryWrapper<ProductionPlan> wrapper = new QueryWrapper<>();
        wrapper.apply("DATE_FORMAT(create_time, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m')");
        return (int) this.count(wrapper);
    }

    @Override
    public ProductionPlan selectBom(String planId) {
        ProductionPlan productionPlans = baseMapper.selectBom(planId);
        return productionPlans;
    }

    @Override
    public List<ProductionPlan> selectByPlan() {
        return baseMapper.selectByPlan();
    }

}
